package com.cardgame.cards;

import java.util.Collections;
import java.util.Vector;

import com.cardgame.constants.Constants;

public class Deck {
	
	@SuppressWarnings("unchecked")
	private Vector cardDeck = null;
	
	
	public int getDeckSize()
	{
		return cardDeck.size();
	}
	
	/*
	 * Initialise the deck by creating all the card and shuffle the deck
	 */
	@SuppressWarnings("unchecked")
	public void initDeck()
	{
		cardDeck = new Vector();
		
		for(int i = 0; i < Constants.SwordNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.SwordName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeWeapon);
			card.setDistance(1);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.SpearNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.SpearName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeWeapon);
			card.setDistance(2);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.BowNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.BowName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeWeapon);
			card.setDistance(3);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.ShieldNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.ShieldName);
			card.setTarget(Constants.targetNone);
			card.setType(Constants.typeShield);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.PotionNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.PotionName);
			card.setTarget(Constants.targetTeam);
			card.setType(Constants.typePotion);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.InvasionNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.InvasionName);
			card.setTarget(Constants.targetEveryoneElse);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.AmageddonNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.AmageddonName);
			card.setTarget(Constants.targetEveryoneElse);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.RevelationNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.RevelationName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.FateNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.FateName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.PoisonNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.PoisonName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.GenerosityNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.GenerosityName);
			card.setTarget(Constants.targetEveryone);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.TruceNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.TruceName);
			card.setTarget(Constants.targetEveryone);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.SilenceNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.SilenceName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.SpiritNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.SpiritName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.HexNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.HexName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.NegationNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.NegationName);
			card.setTarget(Constants.targetTeam);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.CurseNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.CurseName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.DoubleEdgeNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.DoubleEdgeName);
			card.setTarget(Constants.targetEnemy);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.RouletteNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.RouletteName);
			card.setTarget(Constants.targetEveryone);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.WheelNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.WheelName);
			card.setTarget(Constants.targetSelf);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.SizeMattersNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.SizeMattersName);
			card.setTarget(Constants.targetEveryoneElse);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		for(int i = 0; i < Constants.ShallowNumber; i++)
		{
			Card card = new Card();
			card.setName(Constants.ShallowName);
			card.setTarget(Constants.targetTeam);
			card.setType(Constants.typeSpell);
			cardDeck.add(card);
		}
		
		Collections.shuffle(cardDeck);
	}
	
	
	/*
	 * get the next card from the deck
	 */
	public Card getNextCard()
	{
		Card card = (Card) cardDeck.lastElement();
		cardDeck.remove(getDeckSize() - 1);
		
		if(getDeckSize() == 0)
		{
			initDeck();
		}
		
		return card;
	}
	
	
	public Deck()
	{
		
	}

}
